<?php
/**
* 微信公众平台 PHP SDK
*
* @author CuiHao <cuihao871120@gmail.com>
*/
namespace Wechat\API;

use Wechat\Core;

//微信接口基础类
class CustomMenu extends Core
{
    private $err_code;

    private $err_msg;

    public function getErrCode() {
        return $this->err_code;
    }

    public function setErrCode($err_code) {
        $this->err_code = $err_code;
    }

    public function getErrMsg() {
        return $this->err_msg;
    }

    public function setErrMsg($err_msg) {
        $this->err_msg = $err_msg;
    }

    //创建菜单
    public function create($menu) {
        if ($token = $this->GetAccessToken()) {
            $url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=" . $token;
            $result = $this->Post($url,$menu);
            if ($result['errcode'] == 0) {
                return true;
            } else {
                $this->setErrCode($result['errcode']);
                $this->setErrMsg($result['errmsg']);
                return false;
            }
        } else {
            return false;
        }
    }

    //查看菜单
    public function show() {
        if ($token = $this->GetAccessToken()) {
            $url = "https://api.weixin.qq.com/cgi-bin/menu/get?access_token=" . $token;
            $result = $this->Get($url);
            if (!isset($result['errcode'])) {
                return $result;
            } else {
                $this->setErrCode($result['errcode']);
                $this->setErrMsg($result['errmsg']);
                return false;
            }
        } else {
            return false;
        }
    }

    //删除菜单
    public function delete() {
        if ($token = $this->GetAccessToken()) {
            $url = "https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=" . $token;
            $result = $this->Get($url);
            if (isset($result['errcode'])) {
                return true;
            } else {
                $this->setErrCode($result['errcode']);
                $this->setErrMsg($result['errmsg']);
                return false;
            }
        } else {
            return false;
        }
    }
}